package com.hbnu.controller;

import com.hbnu.bean.Door;
import com.hbnu.service.DoorService;
import com.hbnu.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: hjx
 * @Date: 2023/4/19 09:36
 * @Description:门店管理模块
 */
@Controller
public class DoorController {
    @Resource
    private DoorService doorService;

    //查询所有门店信息
    @RequestMapping("/doorList")
    public String findAllDoors(Model model) {
        List<Door> doorList = doorService.findAllDoors();
        //将所有门店信息添加到model对象中，返回给前端
        model.addAttribute("list", doorList);
        return "door_list";
    }

    //添加门店
    @RequestMapping(value = "/doorAdd", produces = {"text/html;charset=UTF-8;", "application/json;charset=UTF-8;"})
    public String NewDoorAdd(Door door) {
        doorService.NewDoorAdd(door);
        return "redirect:/doorList";//重定向
//        return "forward:/doorList";//转发
    }

    //删除门店
    @RequestMapping("/doorDelete")
    public String DeleteDoorById(Integer id) {
        doorService.DeleteDoorById(id);
        return "redirect:/doorList";
    }

    //先对需要修改的门店进行id查询
    @RequestMapping("/doorInfo")
    //先根据id查询需要修改的id，然后回传需要修改的页面
    public String doorInfo(Integer id, Model model) {
        Door door = doorService.findDoorById(id);
        //存储到door中返回前端
        model.addAttribute("door", door);
        //回传后端doorupdate方法
        return "door_update";
    }

    @RequestMapping("/doorUpdate")
    public String UpdateDoor(Door door) {
        doorService.UpdateDoorById(door);
        return "redirect:/doorList";
    }

}

